package servise;



import java.util.ArrayList;
import java.util.List;

import dao.TblAdvertAddressDao;
import pojo.TblAdvertAddress;
import vo.TblAdvertAddressVo;

public class TblAdvertAddressService {
	private TblAdvertAddress tblAdvertAddress = new TblAdvertAddress();;

	public TblAdvertAddress getTblAdvertAddress() {
		return tblAdvertAddress;
	}

	public void setTblAdvertAddress(TblAdvertAddress tblAdvertAddress) {
		this.tblAdvertAddress = tblAdvertAddress;
	}

	public TblAdvertAddressService(TblAdvertAddress tblAdvertAddress) {
		super();
		this.tblAdvertAddress = tblAdvertAddress;
	}
	
	public TblAdvertAddressService() {
		super();
		// TODO Auto-generated constructor stub
	}

	public void insertTblAdvertAddress(TblAdvertAddressVo tblAdvertAddressVo){
		try {
			tblAdvertAddress.setAdvertName(tblAdvertAddressVo.getAdvertName());
			tblAdvertAddress.setDefPath(tblAdvertAddressVo.getDefPath());
			tblAdvertAddress.setDefType(tblAdvertAddressVo.getDefType());
			tblAdvertAddress.setHeight(tblAdvertAddressVo.getHeight());
			tblAdvertAddress.setNotes(tblAdvertAddressVo.getNotes());
			tblAdvertAddress.setWidth(tblAdvertAddressVo.getWidth());

			TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
			tblAdvertAddressDao.insertTblAdvertAddress(tblAdvertAddress);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public List<TblAdvertAddressVo> findTblAdvertAddressByPageList(TblAdvertAddressVo tblAdvertAddressVo){
		List<TblAdvertAddressVo> tblAdvertAddressVoList = new ArrayList();
		//查出总的记录数目
		TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
		int totalIterm = tblAdvertAddressDao.findTblAdvertAddressNumList(tblAdvertAddressVo);
		//计算页数
		int pageNum = totalIterm/tblAdvertAddressVo.getSizePerPage()+(totalIterm%tblAdvertAddressVo.getSizePerPage()==0?0:1);
		tblAdvertAddressVo.setTotal(pageNum);
		if(tblAdvertAddressVo.getCurPage()==null||tblAdvertAddressVo.getCurPage()==0){
			tblAdvertAddressVo.setCurPage(1);
		}
		tblAdvertAddressVoList = tblAdvertAddressDao.findTblAdvertAddressByPageList(tblAdvertAddressVo);
		return tblAdvertAddressVoList;
	}
	
	public List<TblAdvertAddressVo> findTblAdvertAddressList(TblAdvertAddressVo tblAdvertAddressVo){
		List<TblAdvertAddressVo> tblAdvertAddressVoList = new ArrayList();
		TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
		tblAdvertAddressVoList = tblAdvertAddressDao.findTblAdvertAddressList(tblAdvertAddressVo);
		
		return tblAdvertAddressVoList;
	}
	public void deltctAdvertAddress(String[] selectedId){
		if(selectedId==null||selectedId.length==0){
			return;
		}
		String ids = "'"+selectedId[0]+"'";
		for(int i=1;i<selectedId.length;i++){
			ids +=",'"+selectedId[i]+"'";
		}
		TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
		tblAdvertAddressDao.delectAdvertAddress(ids);
	}
	public TblAdvertAddressVo searchUpdateAdvertAddress(TblAdvertAddressVo tblAdvertAddressVo){
		
		TblAdvertAddressVo tblAdvertAddressVoQuery = new TblAdvertAddressVo();
		TblAdvertAddress tblAdvertAddress = new TblAdvertAddress();
		TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
		
		tblAdvertAddress = tblAdvertAddressDao.searchUpdateAdvertAddress(tblAdvertAddressVo);
		
		tblAdvertAddressVoQuery.setAdvertName(tblAdvertAddress.getAdvertName());
		tblAdvertAddressVoQuery.setDefPath(tblAdvertAddress.getDefPath());
		tblAdvertAddressVoQuery.setDefType(tblAdvertAddress.getDefType());
		tblAdvertAddressVoQuery.setHeight(tblAdvertAddress.getHeight());
		tblAdvertAddressVoQuery.setId(tblAdvertAddress.getId());
		tblAdvertAddressVoQuery.setNotes(tblAdvertAddress.getNotes());
		tblAdvertAddressVoQuery.setWidth(tblAdvertAddress.getWidth());
		
		return tblAdvertAddressVoQuery;
		
	}
	public void uptTblAdvertAddress(TblAdvertAddressVo tblAdvertAddressVo){
		try {
			tblAdvertAddress.setAdvertName(tblAdvertAddressVo.getAdvertName());
			tblAdvertAddress.setId(tblAdvertAddressVo.getId());
			tblAdvertAddress.setDefPath(tblAdvertAddressVo.getDefPath());
			tblAdvertAddress.setDefType(tblAdvertAddressVo.getDefType());
			tblAdvertAddress.setHeight(tblAdvertAddressVo.getHeight());
			tblAdvertAddress.setNotes(tblAdvertAddressVo.getNotes());
			tblAdvertAddress.setWidth(tblAdvertAddressVo.getWidth());

			TblAdvertAddressDao tblAdvertAddressDao = new TblAdvertAddressDao();
			tblAdvertAddressDao.uptTblAdvertAddress(tblAdvertAddress);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
